﻿' ****************************************************************************
' Copyright (C) 2009 Tony George
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
' ****************************************************************************

Module modMain
    Public SelectedTask As ListViewItem

    Public LangDict As Dictionary(Of String, String)

    Public ParentTextBox As TextBox

    Sub addMenuItems(ByVal ParentMenu As ContextMenuStrip, ByVal TextBox As TextBox)
        Dim tsi As ToolStripItem

        tsi = ParentMenu.Items.Add(GetLangString("1900"))
        tsi.Tag = ""
        AddHandler tsi.Click, AddressOf Copy_Click

        tsi = ParentMenu.Items.Add(GetLangString("1901"))
        tsi.Tag = ""
        AddHandler tsi.Click, AddressOf Paste_Click

        ParentMenu.Items.Add(New ToolStripSeparator)

        tsi = ParentMenu.Items.Add(GetLangString("1902"))
        tsi.Tag = "%%T"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1903"))
        tsi.Tag = "%%S"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1904"))
        tsi.Tag = "%SystemDrive%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1905"))
        tsi.Tag = "%SystemRoot%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1906"))
        tsi.Tag = "%ProgramFiles%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1907"))
        tsi.Tag = "%CommonDesktop%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1908"))
        tsi.Tag = "%CommonDocuments%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1909"))
        tsi.Tag = "%AllUsersProfile%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1910"))
        tsi.Tag = "%UserDesktop%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1911"))
        tsi.Tag = "%MyDocuments%"
        AddHandler tsi.Click, AddressOf VarInsert_Click

        tsi = ParentMenu.Items.Add(GetLangString("1912"))
        tsi.Tag = "%UserProfile%"
        AddHandler tsi.Click, AddressOf VarInsert_Click
    End Sub

    Private Sub VarInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim tsi As ToolStripItem = DirectCast(sender, ToolStripItem)
        Dim s As String = tsi.Tag
        Dim startPos As Integer = ParentTextBox.SelectionStart
        ParentTextBox.Text = ParentTextBox.Text.Remove(startPos, ParentTextBox.SelectionLength)
        ParentTextBox.Text = ParentTextBox.Text.Insert(startPos, s)
    End Sub

    Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim tsi As ToolStripItem = DirectCast(sender, ToolStripItem)
        My.Computer.Clipboard.SetText(ParentTextBox.SelectedText)
    End Sub

    Private Sub Paste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim tsi As ToolStripItem = DirectCast(sender, ToolStripItem)
        Dim s As String = tsi.Tag
        Dim startPos As Integer = ParentTextBox.SelectionStart
        ParentTextBox.Text = ParentTextBox.Text.Remove(startPos, ParentTextBox.SelectionLength)
        ParentTextBox.Text = ParentTextBox.Text.Insert(startPos, My.Computer.Clipboard.GetText)
    End Sub

    Function GetLangString(ByVal StringID As String) As String
        Dim value As String = ""
        If LangDict.TryGetValue(StringID, value) Then
            Return value
        End If
        Return ""
    End Function

    Sub AppendString(ByVal StringID As String, ByRef ctrl As Control)
        Dim value As String = ""
        If LangDict.TryGetValue(StringID, value) Then
            ctrl.Text += value + vbNewLine
        End If
    End Sub


End Module
